package com.zyk.scaffold.common.tools.tuple;


import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Tuple {

    /**
     * 二元组
     * @param first
     * @param second
     * @param <A>
     * @param <B>
     * @return
     */
    public static <A, B> TwoTuple<A, B> tuple(A first, B second) {
        return new TwoTuple<A, B>(first, second);
    }

    public static <T> List<TwoTuple<Integer, T>> indexTwoTuple(List<T> list) {
        return indexTwoTuple(list.stream()).collect(Collectors.toList());
    }

    public static <T> Stream<TwoTuple<Integer, T>> indexTwoTuple(Stream<T> stream) {
        AtomicInteger i = new AtomicInteger();
        return stream.map(item -> tuple(i.getAndIncrement(), item));
    }
}
